/* 
    Project     : 48c6c450f1a4a0cc53d9585dc0fee742
    Created on  : Mar 16, 2013, 11:29:15 PM
    Author      : Truong Khuong - khuongxuantruong@gmail.com
    Description :
        Purpose of the stylesheet follows.
*/
var menu=(function(){
    return{
        AddItem:function(){
            $('#gridview').hide();
            $('#detail').show();
            _detail('');
        },
        EditItem:function(type){
            try{
                //var cells = $("#jqxGrid").jqxGrid('getselectedcells');
                var rowindex = $('#jqxGrid').jqxGrid('getselectedrowindex');
                var _id=undefined,url,data,obj;
                if(rowindex>-1){
                    var _dataRow=$("#jqxGrid").jqxGrid('getrowdata', rowindex);
                    _id=_dataRow._id===undefined?(_dataRow.ID===undefined?_dataRow.ProductID:_dataRow.ID):_dataRow._id;
                    if(_id!==undefined){
                        if(_id !== $("#news_id").val()){
                            _detail(_id);
                        }else{
                                $(".frmjqxgrid").hide();
                                $(".frmeditting").show();
                                $(".group-events.g").hide();
                                $(".group-events.e").show();
                        }
                    }else{
                        uiMessage("Row ID is not defined.");
                    }
                }else{
                    uiMessage("No row selected. Please select one or more rows.");
                }
            }catch(e){
                uiMessage(e.message);
            }
        },
        Save:function(){
            tinyMCE.triggerSave(false,false);
            if( $('#news_frm').validationEngine('validate') === false)return;
            new backend({
                url         :   base_url+"admincp/content/save",
                data        :   $('#news_frm').serialize(),
                callback    :   function(data){
                    if(data.result<0){
                        new bckdialog({type:'error'}).open(data.message);
                    }else{
                        uiMessage(data.message);
                        $('#gridview').show();
                        $('#detail').hide();
                        $(".group-events.e").hide();
                        $(".group-events.g").show();
                        $("#jqxGrid").jqxGrid('updatebounddata');
                    }
                    console.log(data);
                }
            }).call();
        },
        Cancel:function(){
            $('#gridview').show();
            $('#detail').hide();
            $(".group-events.e").hide();
            $(".group-events.g").show();
        },
        DeleteItem:function(){

        },
        RestoreItem:function(){

        },
        PublicItem:function(){

        },
        PrivateItem:function(){

        },
        Setting:function(){
            bckdialog({
                message:$('#window-sOpt'),
                icon:"<img class='p-a t-7 l-8' src='/libraries/images/16/option.gif'/>",
                title:'Setting'
            }).open();
        },
        Refresh:function(){
            $("#jqxGrid").jqxGrid('updatebounddata');
        }
    };
}());

function handleEvents(){
    try{
//        $("#jqxGrid").bind('rowselect', function (event) {
//            var rowData=$("#jqxGrid").jqxGrid('getrowdata', event.args.rowindex);
//            var ID = rowData._id;
//            $("#detail").load(base_url + "admincp/permission/detail/"+ID);
//            console.log(rowData);
//        });
    }catch(e){
        tipMessage(e.message);
    }
}

$(document).ready(function () {
    
});